package com.dys.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @className: com.dys.servlet.Servlet01
 * @description: Java Server Pages 动态网页技术标准
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/09/23 20:34
 */
@WebServlet(urlPatterns = "/servlet01.do")
public class Servlet01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // http://localhost:8080/servlet_jsp01_Web_exploded/servlet01.do?rows=10&cols=5
        int row = Integer.parseInt(req.getParameter("rows"));
        int col = Integer.parseInt(req.getParameter("cols"));
        StringBuilder sb = new StringBuilder();
        sb.append("<html lang='en'><head><meta charset='UTF-8'><title>Title</title><style>");
        sb.append("table{border: 1px solid green;width: 50%;margin: 0px auto;}");
        sb.append("table td{border: 1px solid blue;}</style></head><body><table>");
        for (int i = 1; i <= row; i++) {
            sb.append("<tr>");
            for (int j = 1; j <= col; j++) {
                sb.append("<td>");
                sb.append(String.valueOf(i));
                sb.append(String.valueOf(j));
                sb.append("</td>");
            }
            sb.append("</tr>");
        }
        sb.append("</table></body></html>");
        // 设置响应内容和编码
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");
        // 响应内容给浏览器
        PrintWriter writer = resp.getWriter();
        writer.print(sb.toString());
    }
}
